package com.binsearch;

public class BinSerach {
	
	public int binSearch(int[] a , int key , int low , int high) {
		
		int mid = (low + high ) /2 ;
		while (low <= high ) {
			if (a[mid] == key ) {
				return mid;
			}
			if (a[mid] > key ) {
				high = mid -1 ;
				mid = (low + high ) / 2;
			}
			if (a[mid] < key ) {
				low = mid + 1;
				mid = (low + high ) / 2;
			}
			
		}
		
		return -1;
	}
	
	public static void main(String[] args) {
		
		int[] a = {1,2,3,4,5,6,9};
		BinSerach binSerach = new BinSerach();
		
		int binSearchs = binSerach.binSearch(a, 3, 0, a.length - 1);
		System.out.println(binSearchs);
	}
}
